package com.yzt.index;

import android.view.View;
import android.widget.TextView;

import com.yzt.zhuju.dialog.CenterBaseDialog;
import com.yzt.zhuju.network.AresSubscriber;
import com.yzt.zhuju.network.biz.BizLayer;
import com.yzt.zhuju.widget.tuiview.TUIImageView;
import com.yzt.zhuju.widget.tuiview.TUITextView;
import com.yzt.p_base.utils.ToastUtil;

/**
 * author : bob
 * date   : 2023/2/8
 * desc   : 签到弹窗
 */
public class SignInDialog extends CenterBaseDialog {

    private TUIImageView[] img_sign_bg;

    private TUITextView[] tv_sign_reward;

    private TUIImageView imgTip;

    private TextView tvSignDay;

    @Override
    public int getLayoutRes() {
        return R.layout.dialog_sign_in;
    }

    @Override
    public void bindView(View v) {

        img_sign_bg[0] = findViewById(R.id.img_sign_bg1);
        img_sign_bg[1] = findViewById(R.id.img_sign_bg2);
        img_sign_bg[2] = findViewById(R.id.img_sign_bg3);
        img_sign_bg[3] = findViewById(R.id.img_sign_bg4);
        img_sign_bg[4] = findViewById(R.id.img_sign_bg5);
        img_sign_bg[5] = findViewById(R.id.img_sign_bg6);
        img_sign_bg[6] = findViewById(R.id.img_sign_bg7);

        tv_sign_reward[0] = findViewById(R.id.tv_sign_reward1);
        tv_sign_reward[1] = findViewById(R.id.tv_sign_reward2);
        tv_sign_reward[2] = findViewById(R.id.tv_sign_reward3);
        tv_sign_reward[3] = findViewById(R.id.tv_sign_reward4);
        tv_sign_reward[4] = findViewById(R.id.tv_sign_reward5);
        tv_sign_reward[5] = findViewById(R.id.tv_sign_reward6);
        tv_sign_reward[6] = findViewById(R.id.tv_sign_reward7);

        imgTip = findViewById(R.id.img_tip);
        tvSignDay = findViewById(R.id.tv_sign_day);

        findViewById(R.id.img_tip).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                modifySignTip(imgTip.isSelected());
            }
        });

        findViewById(R.id.img_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismissAllowingStateLoss();
            }
        });

        findViewById(R.id.tv_sign).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                touchSign();
            }
        });
    }

    /**
     * 点击签到
     */
    private void touchSign() {
        BizLayer.getInstance().getAccountModule().touchSign( new AresSubscriber<Object>() {
            @Override
            protected void onSuccess(Object userInfo) {
                ToastUtil.showMessage(getString(R.string.sign_success));
            }

            @Override
            protected void onError(int code, String info) {
                super.onError(code, info);
            }
        });
    }

    /**
     * 修改签到提醒状态
     */
    private void modifySignTip(boolean isSelect) {
        BizLayer.getInstance().getAccountModule().modifySignTip(2, new AresSubscriber<Object>() {
            @Override
            protected void onSuccess(Object userInfo) {
                ToastUtil.showMessage(getString(R.string.sign_tip_modify_success));
            }

            @Override
            protected void onError(int code, String info) {
                super.onError(code, info);
            }
        });
    }
}
